package com.ruoyi.web.controller.swimming;

import java.util.List;

import com.ruoyi.swimming.domian.Natatorium;
import com.ruoyi.swimming.service.INatatoriumService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 泳馆Controller
 * 
 * @author ruoyi
 * @date 2021-07-17
 */
@RestController
@RequestMapping("/system/natatorium")
public class NatatoriumController extends BaseController
{
    @Autowired
    private INatatoriumService natatoriumService;

    /**
     * 查询泳馆列表
     */
    @PreAuthorize("@ss.hasPermi('system:natatorium:list')")
    @GetMapping("/list")
    public TableDataInfo list(Natatorium natatorium)
    {
        startPage();
        List<Natatorium> list = natatoriumService.selectNatatoriumList(natatorium);
        return getDataTable(list);
    }

    /**
     * 导出泳馆列表
     */
    @PreAuthorize("@ss.hasPermi('system:natatorium:export')")
    @Log(title = "泳馆", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Natatorium natatorium)
    {
        List<Natatorium> list = natatoriumService.selectNatatoriumList(natatorium);
        ExcelUtil<Natatorium> util = new ExcelUtil<Natatorium>(Natatorium.class);
        return util.exportExcel(list, "泳馆数据");
    }

    /**
     * 获取泳馆详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:natatorium:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(natatoriumService.selectNatatoriumById(id));
    }

    /**
     * 新增泳馆
     */
    @PreAuthorize("@ss.hasPermi('system:natatorium:add')")
    @Log(title = "泳馆", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Natatorium natatorium)
    {
        return toAjax(natatoriumService.insertNatatorium(natatorium));
    }

    /**
     * 修改泳馆
     */
    @PreAuthorize("@ss.hasPermi('system:natatorium:edit')")
    @Log(title = "泳馆", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Natatorium natatorium)
    {
        return toAjax(natatoriumService.updateNatatorium(natatorium));
    }

    /**
     * 删除泳馆
     */
    @PreAuthorize("@ss.hasPermi('system:natatorium:remove')")
    @Log(title = "泳馆", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(natatoriumService.deleteNatatoriumByIds(ids));
    }
}
